package com.wash.shoes.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wash.shoes.domain.dto.RegionTransactionDetailDto;
import com.wash.shoes.domain.dto.ShopStsXcxDto;
import com.wash.shoes.domain.vo.RegionDistributorVo;
import com.wash.shoes.domain.vo.RegionTransactionDetailVo;
import com.wash.shoes.domain.vo.StsOrderVo;
import com.wash.shoes.entity.RegionTransactionDetailPo;
import com.wash.shoes.page.PageFactory;
import com.wash.shoes.service.RegionTransactionDetailService;
import com.wash.shoes.mapper.RegionTransactionDetailMapper;
import com.wash.shoes.util.StsDateInfoUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author jianguoli
 * @description 针对表【os_region_transaction_detail(收支明细,订单变为完成的时候入账)】的数据库操作Service实现
 * @createDate 2025-03-11 14:02:41
 */
@Log4j2
@Service
public class RegionTransactionDetailServiceImpl extends ServiceImpl<RegionTransactionDetailMapper, RegionTransactionDetailPo>
        implements RegionTransactionDetailService {

    @Override
    public List<StsOrderVo> recommendDayIncome(ShopStsXcxDto shopStsXcxDto) {

        List<StsOrderVo> dataList = this.baseMapper.recommendDayIncome(shopStsXcxDto);
        return StsDateInfoUtil.processEmptyDays(dataList, shopStsXcxDto);
    }

    @Override
    public StsOrderVo stsOrderInfo(ShopStsXcxDto shopStsXcxDto, Integer status, String type) {
        return this.baseMapper.stsOrderInfo(shopStsXcxDto, status, type);
    }

    @Override
    public Integer cancelTransaction(String orderId) {

        RegionTransactionDetailPo po = this.baseMapper.getByOrderId(orderId);
        if (po == null) {
            return 0;
        }
        po.setStatus(2);
        this.baseMapper.updateById(po);
        log.info("cancelTransaction {}", po);
        return 1;
    }


    @Override
    public List<RegionTransactionDetailPo> getUniFinishDis() {
        return this.baseMapper.getUniFinishDis();
    }

    @Override
    public Page<RegionTransactionDetailPo> incomeExpenseList(ShopStsXcxDto shopStsXcxDto) {
        Page<RegionTransactionDetailPo> page = PageFactory.defaultPage();
        List<RegionTransactionDetailPo> dataList = baseMapper.incomeExpenseList(page, shopStsXcxDto);
        page.setRecords(dataList);
        return page;
    }

    @Override
    public RegionTransactionDetailPo getUserOutProcess(String userId) {
        return this.baseMapper.getUserOutProcess(userId);
    }

    /**
     * 通过用户ID与状态查询体现记录
     * @param userId
     * @return
     */
    @Override
    public List<RegionTransactionDetailPo> getUserOutProcessByStatusAndUserId(String userId) {
       return baseMapper.queryUserOutProcessByStatusAndUserId(userId);
    }

    @Override
    public Page<RegionTransactionDetailVo> pageList(RegionTransactionDetailDto regionTransactionDetailDto) {
        Page<RegionTransactionDetailVo> page = PageFactory.defaultPage();
        List<RegionTransactionDetailVo> dataList = baseMapper.pageList(page, regionTransactionDetailDto);
        page.setRecords(dataList);
        return page;
    }
}




